{extend name="public/layout"}
{block name="head"}
{:_css('static/css/weui.css')}
{:_css('css/weui2.css')}
{/block}
{block name="title"}疑问解答{/block}
{block name="content"}

<div class="form mt10" id="form1">
    <div class="flex border-b">
        <label for="username">姓名</label>
        <div class="flex-con">
            <input type="text" class="form-control" name="username" id="username" placeholder="请输入联系人">
        </div>
    </div>
    <div class="flex border-b">
        <label for="telephone">联系电话</label>
        <div class="flex-con">
            <input type="tel" class="form-control" name="telephone" id="telephone" placeholder="请输入联系电话">
        </div>
    </div>
    <div class="mt10 border-t border-b">
        <textarea name="question"  class="form-control text-left" id="question" rows="5" placeholder="请输入问题内容"></textarea>
    </div>
</div>

<div class="btn-area">
    <div id="submitBtn" class="bg-primary btn-block btn">提交问题</div>
</div>

<div class="footer-fixed">客服电话: {:ccnn_sys_setting('客服电话','')}</div>

{:_js('static/layermobile/layer.js')}
{:_js('js/phone.js')}
{:_js('static/js/zepto.min.js')}
{:_js('static/js/weui.js')}
{:_js('js/picker.js')}


<script>
    $(function () {
        $('#submitBtn').on('click', function () {
            var postData = {};
            var is_valid = true;
            $('#form1').find('input[name],textarea[name]').each(function () {
                if (!this.value.trim() && this.name != 'address') {
                    is_valid = false;
                    ui.msg($(this).attr('placeholder'));
                    return false;
                }
                postData[this.name] = this.value.trim();
            });
            var len = postData['question'].length;
            if(len<50 || len > 500){
                ui.msg('问题内容必须在50到100个字符之间');
                return;
            }
            if (is_valid) {
                ui.toast.show();
                $.post("{:U('save')}", postData, function (rt) {
                    ui.toast.hide();
                    if (rt.status == 1) {
                        location.href = "{:U('index/index')}";
                    } else {
                        ui.msg(rt.info);
                    }
                }, 'json');
            }
        });
    });
</script>

{/block}
